﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Presentation.Shell.Interfaces;
using System.Collections.ObjectModel;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;

namespace VPL.Shell
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class ShellWindow : Window
    {
        public ShellWindow(ILogonService logonService, IRegionManager regionManager, IUnityContainer container)
        {
            InitializeComponent();

            this.LogonService = logonService;
            this.RegionManager = regionManager;
            this.Container = container;

            var mainMenu = Container.Resolve<MainMenu>();

            Microsoft.Practices.Prism.Regions.RegionManager.SetRegionManager(this, regionManager);

            while (true)
            {
                var logonMenu = Container.Resolve<Logon>();
                logonMenu.ShowDialog();
                if (logonMenu.LogonResult != true)
                {
                    MessageBox.Show("Please enter a valid user name and password", "Invalid Logon Details",
                                MessageBoxButton.OK);
                }
                else
                {
                    if (mainMenu != null)
                        mainMenu.textBlock1.Text = logonMenu.textBox1.Text;
                    break;
                }
                    
            }
           
            regionManager.Regions["MainRegion"].Add(mainMenu);
            regionManager.Regions["MainRegion"].Activate(mainMenu);

            var val = this.MainRegionHolder.GetValue(Microsoft.Practices.Prism.Regions.RegionManager.RegionNameProperty);
        }

        public ILogonService LogonService { get; set; }
        public IRegionManager RegionManager { get; set; }
        public IUnityContainer Container { get; set; }
    }
}
